<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="discussion-macros.html"/>
  <xi:include href="layout.html"/>
  <?python
    from trac.util.datefmt import format_datetime, pretty_timedelta
    from multiproject.core.configuration import conf
  ?>
  <head>
    <title>Topic List</title>

    <script type="text/javascript">
    function clickNewTopic()
    {
        document.newtopicform.newtopic.click();
    }
    function blurSearchBar()
    {
        if (document.fullsearch.q.value == "Search in topics") {
                document.fullsearch.q.style.fontStyle="italic";
        }
        if (document.fullsearch.q.value == "") {
            document.fullsearch.q.value = "Search in topics";
            document.fullsearch.q.style.fontStyle="italic";
        }

    }
    function focusSearchBar() {

        document.fullsearch.q.style.fontStyle="normal";
        if (document.fullsearch.q.value == "Search in topics") {
                document.fullsearch.q.value = '';
        }
    }
    $(document).ready(function() {
        $("#sortby option[name='${discussion.order}']").attr('selected', 'selected');
        $("#showrows option[name='${discussion.paginator.max_per_page}']").attr('selected', 'selected');
    });

    </script>
    <link rel="stylesheet" type="text/css" href="${href('/chrome/multiproject/css/jquery-ui.css')}" />
    <script type="text/javascript" src="${href('/chrome/multiproject/js/jquery-ui.js')}"></script>
  </head>

  <body>

    <xi:include href="discussion-header.html"/>

    <div id="content" class="discussion" style="position:static; padding-bottom: 4em;">
      <div id="${discussion.mode}" class="${discussion.mode}">

        <div class="breadcrumb">
          <a href="${href.discussion()}">
            <span>Forum List &gt;</span>
          </a>
        </div>

        <div id="subdesc">
            <h1 class="subpage_title">${discussion.forum.subject}</h1>
            <p>${discussion.forum.description}</p>
        </div>

        <div class="buttons">
          <form py:if="(discussion.forum.name != conf.news_forum_name and 'DISCUSSION_APPEND' in perm) or (discussion.forum.name == conf.news_forum_name and 'DISCUSSION_ANNOUNCEAPPEND' in perm)" name="newtopicform" method="post" action="${href.discussion('forum', discussion.forum.id)}">
            <div>
              <span class="primaryButton">
                <input type="submit" name="newtopic" value="Create New Topic" />
              </span>
              <input type="hidden" name="forum" value="${discussion.forum.id}"/>
              <input type="hidden" name="discussion_action" value="add"/>
            </div>
          </form>
          <div py:if="discussion.authemail" id="subscribe_button" >
              <py:choose>
                  <py:when test="discussion.authname in discussion.forum.subscribers or discussion.authemail in discussion.forum.subscribers">
                      <span class="secondaryButton" style="width:90px;">
                          <input type="submit" value="Unsubscribe" id="subscribe"
                          onclick="subscribe_user('${req.href.discussion('ajax', 'forum',
                          discussion.forum.id)}', '${discussion.authname}', 'False')"/>
                      </span>
                  </py:when>
                  <py:otherwise>
                      <span class="secondaryButton" style="width:90px;">
                          <input type="submit" value="Subscribe" id="subscribe"
                          onclick="subscribe_user('${req.href.discussion('ajax', 'forum',
                          discussion.forum.id)}', '${discussion.authname}', 'True')"/>
                      </span>
                  </py:otherwise>
              </py:choose>
          </div>
          <form py:if="'DISCUSSION_ADMIN' in perm and discussion.forum.name != conf.news_forum_name" method="post" action="${href.discussion()}">
            <div>
              <span class="secondaryButton" style="width:90px;">
                  <input type="submit" name="deleteforum" value="Delete Forum" onclick="return confirm('Do you really want to delete this forum?')"/>
              </span>
            <input type="hidden" name="forum" value="${discussion.forum.id}"/>
            <input type="hidden" name="discussion_action" value="delete"/>
          </div>
        </form>
        </div>

        <div id="searchbar">

            <form method="get" action="${href.discussion()}/forum/${discussion.forum.id}" id="showsettings" name="showsettings">
                    <div id="sortingbox" name="order">
                    <label id="sorttxt"  for="sortby">
                        <span id="sortbytitle">Sort by:</span>
                    </label>
                        <select class="selectMenu" id="sortby" name="order">
                           <option name="subject" value="subject">Subject</option>
                           <option name="author" value="author">Author</option>
                           <option name="replies" value="replies">Replies</option>
                           <option name="viewcount" value="viewcount">Views</option>
                           <option name="lastreply" value="lastreply">Last Post</option>
                       </select>
                       <button type="submit" id="go">${_('Go')}</button>
                    </div>

                    <div id="sortingbox">
                    <label id="sorttxt" for="showrows">
                        <span id="showrowstitle">Show rows:</span>
                    </label>
                        <select class="selectMenu" id="showrows" name="rowsperpage">
                          <option py:for="num in [10,20,50,100,150,200]" name="${num}" value="${num}">${num}</option>
                       </select>
                    </div>

            </form>

            <form method="get" action="${req.base_path}/search" id="fullsearch" name="fullsearch">
              <div id="searchbox">
                <input type="text" value="Search in topics" name="q" id="q" onclick="focusSearchBar()" onblur="blurSearchBar()"/>
                <input type="hidden" value="1" name="noquickjump" />
                <input type="hidden" checked="checked" name="discussion" id="discussion" value="on" />
                <button type="submit" value="" id="submit" />
              </div>
            </form>
        </div>

        <h2 class="report-result title">
        <div class="topic-title">Topic list</div>
            <py:choose>
                <py:when test="discussion.paginator.num_items == 0">
                    <div id="topic-count-header">No topics - Page 1 of 1</div>
                </py:when>
                <py:when test="discussion.paginator.num_items == 1">
                    <div id="topic-count-header">1 topic - Page ${discussion.paginator.current_page.string} of ${discussion.paginator.num_pages}</div>
                </py:when>
                <py:otherwise>
                    <div id="topic-count-header">${discussion.paginator.num_items} topics - Page ${discussion.paginator.current_page.string} of ${discussion.paginator.num_pages}</div>
                </py:otherwise>
            </py:choose>
        </h2>

        <xi:include href="topic-list-classic.html"/>

        <xi:include py:with="paginator = discussion.paginator" href="page_index.html" />

        <div py:if="discussion.moderator or discussion.authemail"
          class="subscription">
          <a name="subscription"></a>
          <form method="post" action="${href.discussion('forum',
            discussion.forum.id)}">
            <fieldset id="subscription">

              <div py:if="discussion.moderator">
              <legend>Manage subscribers</legend>
                <br/>

                <py:choose>
                  <py:when test="(len(discussion.forum['subscribers']) == 0)">
                    <div id="nosubs" name="nosubs" style="display:block;">
                      No subscribers
                    </div>
                  </py:when>
                  <py:otherwise>
                    <div id="nosubs" name="nosubs" style="display:none;">
                      No subscribers
                    </div>
                  </py:otherwise>
                </py:choose>

                <py:choose>
                  <select py:when="(len(discussion.forum['subscribers']) == 0)" id="subscribers"
                    name="subscribers" multiple="on" style="display:none;">
                  </select>
                  <select py:when="len(discussion.forum['subscribers']) > 0 and 7 >
                    len(discussion.forum['subscribers'])" id="subscribers" name="subscribers"
                    multiple="on">
                    <py:for each="user in discussion.forum['subscribers']">
                      <py:choose>
                        <option value="${user}" selected="selected">${user}</option>
                      </py:choose>
                    </py:for>
                  </select>
                  <select py:when="len(discussion.forum['subscribers']) > 6" id="subscribers"
                    name="subscribers" size="6" multiple="on">
                    <py:for each="user in discussion.forum['subscribers']">
                      <py:choose>
                        <option value="${user}" selected="selected">${user}</option>
                      </py:choose>
                    </py:for>
                  </select>
                </py:choose>
                <br/>
              </div>

              <div py:if="discussion.moderator" style="margin-bottom:10px;">
                <label for="unregistered_subscribers">Add subscribers (usernames or email addresses):</label>
                <br/>
                <input type="text" id="unregistered_subscribers"
                  name="unregistered_subscribers" />
                  <span class="secondaryButton">
                    <input type="button" id="addsubscriber" name="addsubscriber" value="Add" style="width:120px;"/>
                  </span>
                <br/>
              </div>

              <div py:if="discussion.moderator" style="float:left;" class="buttons">
                <input type="hidden" name="discussion_action"
                  value="subscriptions-post-edit"/>
                <span class="secondaryButton">
                    <input type="submit" name="editsubscribers" value="Save" style="width:120px;"/>
                </span>
              </div>
            </fieldset>
          </form>
        </div>
      </div>
    </div>

    <xi:include href="rss_feed.html"/>

    <xi:include href="discussion-footer.html"/>

    <script type="text/javascript">
        var subsfield = $("#unregistered_subscribers");
        var requester = function (request, response) {
            // Show loader class until response is shown
            subsfield.addClass('loading');
            var keyword = subsfield.val();
            $.getJSON("${req.base_path}/userautocomplete", {q:keyword, fields:'username'}, function(data){
                var ulist = [];
                $.each(data, function(key, user) {
                    ulist.push(user.username);
                });
                response(ulist);
                subsfield.removeClass('loading');
            });
        };
        subsfield.autocomplete({source:requester, minLength:3});
    </script>
  </body>
</html>
